/*
** calc.c for  in /u/all/caille_c/cu/rendu/c/minitalk/server
** 
** Made by carole cailleux
** Login   <caille_c@epitech.net>
** 
** Started on  Fri Mar 12 17:50:07 2010 carole cailleux
** Last update Wed Mar 17 19:25:40 2010 carole cailleux
*/

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "serv.h"

extern int	gl_pid_cl;

void		calc_octet(int sig, int i, int *val)
{
  if (sig == SIGUSR2)
    {
      if (i < 32)
	{
	  *val += power(2, i);
	  usleep(300);
	}
      else
        *val += power(2, i % 8);
    }
}

void		calc_pid(int *val)
{
  gl_pid_cl = *val;
  *val = 0;
  my_putstr("\n[Connexion opened]\nPID cli = ");
  my_put_nbr(gl_pid_cl);
  my_putchar('\n');
}

void		calc_chara(int *val, int *i)
{
  if (*val)
    my_putchar(*val);
  else if (*val == 0 && *i > 32)
    {
      *i = 0;
      gl_pid_cl = 0;
      my_putstr("\n[Connexion closed]\n\n");
    }
  *val = 0;
}
